<template>
  <div class="box">
    <h2 class="h" style="color:#f49">公告列表</h2>
    <div class="search">
      <!-- input -->
      <el-input class="search-input" v-model="input" placeholder="请输入关键词" clearable />
      <!-- 多选框公告类型 -->
      <el-cascader class="search-checkall" v-model="item" :options="itemVal" @change="handleChange"
        placeholder="选择公告类型" />
        <!-- 时间选择器 -->
      <el-date-picker class="search-data" v-model="date1" type="daterange" range-separator="To"
        start-placeholder="Start date" end-placeholder="End date" :size="size" />

      <!-- 搜索重置 -->
      <div class="search-search">
        <el-button type="primary" @click="search">搜索</el-button>
        <el-button type="info" plain @click="resetting">重置</el-button>

      </div>
    </div>



    <template v-if="data[0]">
      <div class="main">
        <div class="main-tab">
          <el-table :data="data" style="width: 100%;">
           
            <el-table-column prop="" label="序号" />
            <el-table-column prop="name" label="公告标题" />
            <el-table-column prop="type" label="公告分类" />
            <el-table-column v-slot="{ row }" label="发布时间">
              <span> {{ row.time.slice(0, 10) }}</span>
            </el-table-column>

            <el-table-column v-slot="{ row }" label="发布人">
              <span>{{ row.author.username }}</span>
            </el-table-column>

            <el-table-column prop="" label="操作">
              <button>查看</button>
            </el-table-column>
          </el-table>
        </div>



      </div>
    </template>
    <template v-else>
      暂无数据
    </template>



  </div>
</template>

<script setup>
import { ref, onMounted } from "vue"
import axios from "axios"

let input = ref("")//输入框
let item = ref([])//多选框项目
let classes = ref([])//多选框班级
let number = ref()//分数类别
let date1 = ref("")//日期段
let tk = ref("")

let data = ref([])


const itemVal = [//项目类型多选数据
  {
    value: '普通公告',
    label: '普通公告',
  },
  {
    value: '紧急公告',
    label: '紧急公告',
  },
  {
    value: '重要公告',
    label: '重要公告',
  },
  {
    value: '置顶公告',
    label: '置顶公告',
  },
 
]


let ax = (type, url, tk, data) => {//请求方法
  let res = axios({
    url: url,
    method: type,
    headers: {
      token: tk
    },
    data: data
  })

  return res
}

let search = () => {//搜索事件

}

let resetting = () => {//重置事件
  input.value = ""
  item.value = []
  classes.value = []
  number.value = ""
  // data.value = dataCopy.value
}

onMounted(async () => {
  tk.value = JSON.parse(localStorage.getItem("good")).userInfo.token


  // 项目成绩
  let getallgrades = await ax("post", "http://81.69.235.62:3000/api/getannos", JSON.parse(localStorage.getItem("good")).userInfo.token)
console.log("项目成绩", getallgrades)
  if (getallgrades.data.code == 200) {
    data.value = getallgrades.data.result
    console.log("项目成绩", getallgrades);
  }


})

</script>

<style lang="scss" scoped>
.h {
  font-size: 25px;
  font-weight: 600;
}

.search {
  width: 100%;
  height: 50px;
  margin-top: 10px;
  overflow: hidden;

  ::v-deep(div) {
    margin-left: 10px;
  }

  ::v-deep(.search-input, ) {
    width: 250px;

    float: left;
  }

  ::v-deep(.search-checkall) {
    width: 250px;
    height: 35px;
    float: left;
  }

  ::v-deep(.el-date-editor) {
    float: left;
    margin-left: 10px;
  }

  .search-search {
    float: left;
    margin-left: 100px;
  }
}

.main {
  width: 100%;
  height: 100%;
  border: 1px solid gray;
  margin-top: 10px;
  overflow: auto;

  :v-deep(.main-tab) {
    text-align: center;
  }
}

:v-deep(.content) {
  margin: 0;
}
</style>